package com.jalarbee.core.util;

import com.jalarbee.core.util.validation.Validatable;
import com.jalarbee.core.util.validation.ValidationError;
import com.jalarbee.core.util.validation.ValidationResult;

public class Chunk implements Validatable {

	private int start;
	private int size;

	public Chunk(int start, int size) {
		this.size = size;
		this.start = start;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getLastIndex() {
		return start + size - 1;
	}

	public boolean makesSense() {
		if(start >= 0 && size > 0)
			return true;
		return false;
	}

	public ValidationResult validate() throws Exception {
		ValidationResult result = GenericFactory.get(ValidationResult.class);
		if(start < 0 || size <= 0) {
			result.addError(new ValidationError("badChunkSize"));
		}
		return result;
	}
}
